package com.xbongbong.rule.symbol;

import com.alibaba.fastjson.JSONArray;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.rule.symbol.base.AbstractSymbol;
import com.xbongbong.saas.constant.StringConstant;
import org.apache.commons.lang3.StringUtils;

/**
 * 包含判断
 * 适用类型:多行文本/单选
 *
 * @author zheng.li
 **/
public class LikeSymbol extends AbstractSymbol {

    @Override
    public boolean operation() {
        if (StringUtils.isEmpty(value.toString())) {
            return false;
        }
        if (attr.contains(FieldTypeEnum.SUB_FORM.getEsalias()) && attr.contains(StringConstant.POINT)) {
            //子表单
            JSONArray arrayValue = factJson.getJSONArray(attr);
            return arrayValue.stream().anyMatch(v -> v.toString().contains(conditionValue.toString()));
        } else {
            //其他
            return value.toString().contains(conditionValue.toString());
        }
    }
}
